<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>管理控制台</title>
    <% include("header.html"){} %>
    <style>
        td{
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
        .iconfont{
            background-image: none!important;
        }
        span.iconfont{
            margin-right: 6px!important;
        }
    </style>
</head>
<body class="easyui-layout">
<div id="loading" style="position: fixed;top: -50%;left: -50%;width: 200%;height: 200%;background: #fff;z-index: 100;overflow: hidden;">
    <img src="${ctxPath!}/static/easyui/themes/metro/images/loading.gif" style="position: absolute;top: 0;left: 0;right: 0;bottom: 0;margin: auto;"/>
</div>
<!-- begin of header -->
<div class="ui-header" data-options="region:'north',border:false,split:true">
    <div class="ui-header-left">
        <h1><img src="${ctxPath!}/static/img/logo.png" height="50px" style="vertical-align: middle; margin-top: -15px;"/></h1>
    </div>
    <div class="ui-header-right">
        <p><strong>${session.cUser.name!}</strong>，欢迎您！
            | <a href="${ctxPath!}/logout.html">[安全退出]</a></p>
    </div>
</div>
<!-- end of header -->
<!-- begin of sidebar -->
<div class="ui-sidebar" data-options="region:'west',split:true,border:true,title:'导航菜单'">
    <div class="easyui-accordion" data-options="border:false,fit:true">
        <%
            for(menu in menuList){
        %>
            <div title="${menu.name!}" data-options="iconCls:'iconfont iconfont-${menu.icon!}'" style="padding:5px;">
                <ul class="ui-side-tree">
                <%
                    for(subMenu in menu.subPerms){
                %>

                    <%
                        if(isEmpty(subMenu.subPerms)){
                    %>
                        <li iconCls="iconfont iconfont-${subMenu.icon!}"><a href="${ctxPath!}${subMenu.url!}">${subMenu.name!}</a></li>
                    <%
                        } else {
                    %>
                        <li iconCls="iconfont iconfont-${subMenu.icon!}">
                            <span>${subMenu.name!}</span>
                            <ul>
                                <%
                                    for(sub in subMenu.subPerms){
                                %>
                                    <li iconCls="iconfont iconfont-${sub.icon!}"><a href="${ctxPath!}${sub.url!}">${sub.name!}</a></li>
                                <%
                                    }
                                %>
                            </ul>
                        </li>
                    <%
                        }
                    %>
                <%
                    }
                %>
                </ul>
            </div>
        <%
            }
        %>
        <div title="个人中心" data-options="iconCls:'iconfont iconfont-bussinessman'" style="padding:5px;">
            <ul class="ui-side-tree">
                <li iconCls="iconfont iconfont-survey1"><a href="${ctxPath!}/sys/user/editInfo">编辑个人资料</a></li>
                <li iconCls="iconfont iconfont-shuffling-banner"><a href="${ctxPath!}/sys/user/editPw">修改个人密码</a></li>
                <li iconCls="iconfont iconfont-rfq"><a href="${ctxPath!}/policy/viewList">查看法规文件</a></li>
                <li iconCls="iconfont iconfont-viewlist"><a href="${ctxPath!}/notice/viewList">查看通知公告</a></li>
                <li iconCls="iconfont iconfont-comments"><a href="${ctxPath!}/dynamics/viewList">查看工作动态</a></li>
            </ul>
        </div>
    </div>
</div>
<!-- end of sidebar -->
<!-- begin of main -->
<div class="ui-main" data-options="region:'center'">
    <div id="ui-tabs" class="easyui-tabs" data-options="border:false,fit:true">
        <div title="首页" data-options="border:false, closable:false,iconCls:'iconfont iconfont-all',href:'${ctxPath!}/console/index'">

        </div>
    </div>
</div>
<!-- end of main -->
<!-- begin of footer -->
<div class="ui-footer" data-options="region:'south',border:true,split:true">
    &copy; 2016 ZhouTian Tech. All Rights Reserved
</div>
<!-- end of footer -->
<script type="text/javascript">


    /**
     * Name 载入树形菜单
     */
    var trees = $('.ui-side-tree').tree({
        onClick:function(node){
            if($('.ui-side-tree').tree('isLeaf', node.target)) {
                console.log(node.target);
                var adom = node.text;
                var url = $(adom).attr("href");
                var title = $(adom).text();
                var iconClass = node.iconCls;
                if (url == null || url == "" || url == undefined) {
                    return false;
                }
                else {
                    addTab(title, url, iconClass, true);

                }
            }else {
                $('.ui-side-tree').tree('toggle', node.target);
            }
        }
    });

    $(function(){
        $('.ui-side-tree a').on("click",function(){
            var target = $(this).closest(".tree-node")[0];
            var iconCls = "";
            for(var i in trees){
                var node = $(trees[i]).tree('getNode', target);
                if(node != null && node != undefined){
                    iconCls = node.iconCls;
                    break;
                }
            }
            var title = $(this).text();
            var url = $(this).attr('href');
            addTab(title,url,iconCls, true);
            return false;
        });
    });

    //刷新当前标签Tabs
    function RefreshTab(currentTab) {
        currentTab.find("iframe")[0].contentWindow.location.reload();
    }

    /**
     * Name 选项卡初始化
     */
    var tabs = $('#ui-tabs').tabs({
        fit : true,
        border : false,
        tools:[{
            iconCls:'icon-reload',
            border:false,
            handler:function(){
                var tab = $('#ui-tabs').tabs('getSelected');
                RefreshTab(tab);
            }
        }]
    });

    /**
     * Name 添加菜单选项
     * Param title 名称
     * Param href 链接
     * Param iconCls 图标样式
     * Param iframe 链接跳转方式（true为iframe，false为href）
     */
    function addTab(title, href, iconCls, iframe){
        var tabPanel = $('#ui-tabs');
        if(!tabPanel.tabs('exists',title)){
            var content = '<iframe scrolling="auto" frameborder="0"  src="'+ href +'" style="width:100%;height:99.0%;"></iframe>';
            if(iframe){
                tabPanel.tabs('add',{
                    title:title,
                    content:content,
                    iconCls:iconCls,
                    fit:true,
                    closable:true
                });
            }
            else{
                tabPanel.tabs('add',{
                    title:title,
                    href:href,
                    iconCls:iconCls,
                    fit:true,
                    cls:'pd3',
                    closable:true
                });
            }
        }
        else
        {
            tabPanel.tabs('select',title);
            var currentTab = tabPanel.tabs('getTab', title);
            currentTab.find("iframe")[0].contentWindow.location.href= href;
        }
    }
    /**
     * Name 移除菜单选项
     */
    function removeTab(){
        var tabPanel = $('#ui-tabs');
        var tab = tabPanel.tabs('getSelected');
        if (tab){
            var index = tabPanel.tabs('getTabIndex', tab);
            tabPanel.tabs('close', index);
        }
    }



    function reloadTabGrid(title) {
        removeTab();
        if ($("#ui-tabs" ).tabs('exists', title)) {
            $( '#ui-tabs').tabs('select' , title);
            window.top.reload_hse_list.call();
        }
    }
</script>
</body>
</html>
